package com.neuedu.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.neuedu.pojo.Result;
import com.neuedu.pojo.TAdministrator;
import com.neuedu.pojo.TFamily;
import com.neuedu.mapper.TFamilyMapper;
import com.neuedu.service.ITFamilyService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author zhangsan
 * @since 2024-06-17
 */
@Service
public class TFamilyServiceImpl extends ServiceImpl<TFamilyMapper, TFamily> implements ITFamilyService {
    private static int LIMIT=9;
    @Autowired
    TFamilyMapper familyMapper;

    @Override
    public Result findByElderId(int elderId) {
        LambdaQueryWrapper<TFamily> lqw = new LambdaQueryWrapper<>();
        lqw.eq(TFamily::getElderId, elderId)
                .le(TFamily::getFaRelation,LIMIT);
        List<TFamily> families = familyMapper.selectList(lqw);
        return Result.success(families, "查询成功");
    }

    @Override
    public Result modifyFa(TFamily family) {
        family.setUpdateTime(LocalDateTime.now());
        return Result.success(familyMapper.updateById(family),"修改成功");
    }

    @Override
    public Result addFa(TFamily family) {
        family.setCreateTime(LocalDateTime.now());
        family.setUpdateTime(LocalDateTime.now());
        return Result.success(familyMapper.insert(family),"修改成功");
    }
}
